﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    [Serializable]
    public class PhieuKHTraHangDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertPhieuKHTraHang(PhieuKHTraHangDTO PhieuKHTraHang)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[11];
            par[0] = new SqlParameter("@MAKHTH", PhieuKHTraHang.Makhth);
            par[1] = new SqlParameter("@MaNV", PhieuKHTraHang.Manv);
            par[2] = new SqlParameter("@MaKho", PhieuKHTraHang.Makho);
            par[3] = new SqlParameter("@MaKh", PhieuKHTraHang.Makh);
            par[4] = new SqlParameter("@NguoiTra", PhieuKHTraHang.Nguoitra);
            par[5] = new SqlParameter("@MaSoThue", PhieuKHTraHang.Masothue);
            par[6] = new SqlParameter("@DiaChi", PhieuKHTraHang.Diachi);
            par[7] = new SqlParameter("@NgayTra", PhieuKHTraHang.Ngaytra);
            par[8] = new SqlParameter("@ChungTuTra", PhieuKHTraHang.Chungtutra);
            par[9] = new SqlParameter("@GhiChuth", PhieuKHTraHang.Ghichuth);
            par[10] = new SqlParameter("@TongThanhTien", PhieuKHTraHang.Tongthanhtien);
            try
            {
                helper.InsertQuery("sp_insert_phieukhtrahang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdatePhieuKHTraHang(PhieuKHTraHangDTO PhieuKHTraHang)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[11];
            par[0] = new SqlParameter("@MAKHTH", PhieuKHTraHang.Makhth);
            par[1] = new SqlParameter("@MaNV", PhieuKHTraHang.Manv);
            par[2] = new SqlParameter("@MaKho", PhieuKHTraHang.Makho);
            par[3] = new SqlParameter("@MaKh", PhieuKHTraHang.Makh);
            par[4] = new SqlParameter("@NguoiTra", PhieuKHTraHang.Nguoitra);
            par[5] = new SqlParameter("@MaSoThue", PhieuKHTraHang.Masothue);
            par[6] = new SqlParameter("@DiaChi", PhieuKHTraHang.Diachi);
            par[7] = new SqlParameter("@NgayTra", PhieuKHTraHang.Ngaytra);
            par[8] = new SqlParameter("@ChungTuTra", PhieuKHTraHang.Chungtutra);
            par[9] = new SqlParameter("@GhiChuth", PhieuKHTraHang.Ghichuth);
            par[10] = new SqlParameter("@TongThanhTien", PhieuKHTraHang.Tongthanhtien);
            try
            {
                helper.UpdateQuery("sp_update_phieukhtrahang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeletePhieuKHTraHang(string maKHTH)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@maKHTH", maKHTH);
            try
            {
                helper.DeleteQuery("sp_delete_phieukhtrahang", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_PhieuKHTraHang()
        {
            helper = new Helper();
            DataSet ds = helper.SelectQuery("sp_layds_phieukhtrahang");
            return ds;
        }
        #endregion
    }
}